import {createRouter,createWebHashHistory} from "vue-router"
import type { RouteRecordRaw } from 'vue-router'
import {routerList} from "../routeConfig.js"
const routes:RouteRecordRaw[] = []
export const router = createRouter({
  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHashHistory(),

  routes:[
		{
			path: '/login',
			name: 'login',
			component: () => import('@/views/login.vue'),
		},
		{
			path: '/',
			component: () => import('@/views/gameHome/index.vue'),
			name: '/',
		},
	], // `routes: routes` 的缩写
})

const transRoute=(routeData)=>{
	const routes:RouteRecordRaw[] = []
	routeData.forEach((route)=>{
		console.log(loadView(route))
		routes.push({
			path:route.path,
			component:loadView(route),
			name:route.name
		})
	})
	return routes
}
const loadView = (item)=>{
	return ()=> import('@/views/'+item.componentUrl)
}

setTimeout(()=>{
	const anyncRoutes= transRoute(routerList)
	anyncRoutes.forEach(anyncRoute=>{
		router.addRoute(anyncRoute)
	})
},1000)